#include "waterTank.h"

#include <math.h>

WaterTank::WaterTank()
{
    //Caixa de água de 2000 litros
    area = 2;           //em m quadrados
    level = 70;         //em cm
    height = 100;        //em cm
    standartLevel = (1.0*height)/2.0;
    gaugeIn = 2;        //em cm
    gaugeOut = 4;       //em cm
}

WaterTank::~WaterTank() {}

 double WaterTank::WaterTank_Fill(double R, time_t time)   //Bomba garante R(vazão) em toda tubulação = R é cte
 {
    return 100*(R*time)/area;     //100-> de metros para centímetros
 }

 double WaterTank::WaterTank_Clear(double C,time_t time) //R varia, C= coeficiente de descarga
{
    // livro de Hidráulica Básica do Rodrigo de Melo Porto - Capítulo 12: Orifícios, Tubos Curtos e Vertedores
    //T = -integral(de hantigo até hnovo)(A(h)/raíz(h)dh)/(C*Aorifício*raíz(2g))
    return 100*pow(-1.0*G*time*C*PI*pow(0.005*gaugeOut,2)*sqrt(2*GRAVITY)/2*area + sqrt(0.01*level),2);
}

void WaterTank::WaterTank_SetLevel(double level)
{
    this->level = level;
}

void WaterTank::WaterTank_SetStandartLevel(double standartLevel)
{
    this->standartLevel = standartLevel;
}

void WaterTank::WaterTank_SetHeight(double height)
{
    this->height = height;
}

void WaterTank::WaterTank_SetArea(double area)
{
    this->area = area;
}

void WaterTank::WaterTank_SetGaugeIn(double gaugeIn)
{
    this->gaugeIn = gaugeIn;
}

void WaterTank::WaterTank_SetGaugeOut(double gaugeOut)
{
    this->gaugeOut = gaugeOut;
}

double WaterTank::WaterTank_GetLevel(void)
{
    return level;
}

double WaterTank::WaterTank_GetStandartLevel(void)
{
    return standartLevel;
}

double WaterTank::WaterTank_GetHeight(void)
{
    return height;
}

double WaterTank::WaterTank_GetGaugeOut(void)
{
    return gaugeOut;
}
